SIDE = {
    BLUE = coalition.side.BLUE,
    RED = coalition.side.RED,
    NEUTRAL = coalition.side.NEUTRAL
}

-- SSB
USERFLAG:New("SSB"):Set(100)
local FARP_CLIENTS = SET_CLIENT:New():FilterPrefixes("GRIFFIN 前线FARP"):FilterStart()
FARP_CLIENTS:ForEachClient(function(client)
  USERFLAG:New(tostring(client.ClientName)):Set(100) -- disable clients
end)


-- ******************纳尔奇克占领开始
CaptureZone_Narchik = ZONE:New("NarchikZone")
ZoneCaptureCoalition_Narchik = ZONE_CAPTURE_COALITION:New(CaptureZone_Narchik, SIDE.RED)
ZoneCaptureCoalition_Narchik:__Guard(1)

ZoneCaptureCoalition_Narchik:Start(5, 60)

local Narchik_Base = SPAWN:New("GRIFFIN Narchik Base")

function ZoneCaptureCoalition_Narchik:onenterGuarded(From, Event, To) -- 纳尔奇克占领机场事件
  if From ~= To then
    local tempCoalition = self:GetCoalition()
    if tempCoalition == SIDE.BLUE then
      -- 通报
      MessageToAll("====================\n格里芬战情通报:\n" ..
      "格里芬的部队占领了纳尔奇克\n====================",
        10, "格里芬战情通报")
      if Narchik_Base:GetFirstAliveGroup() then
        Narchik_Base:Spawn()
      end
    elseif tempCoalition == SIDE.RED then
      MessageToAll("格里芬战情通报: 铁血占领了纳尔奇克机场", 10, "格里芬战情通报")
    end
  end
end

function ZoneCaptureCoalition_Narchik:OnEnterAttacked() -- 通报正在被进攻
  local beattacked = self:GetCoalition()
  if beattacked == SIDE.BLUE then
    MessageToAll("====================\n格里芬战情通报:\n" ..
    "纳尔奇克正在被铁血进攻\n====================", 10, "格里芬战情通报")
  else
    MessageToAll("====================\n格里芬战情通报:\n" ..
    "格里芬地面部队正在进攻纳尔奇克\n====================", 10,
      "格里芬战情通报")
  end
end

function ZoneCaptureCoalition_Narchik:onenterEmpty() --当玩家清除完目标后生成蓝方以占领
    MessageToAll("====================\n格里芬战情通报:\n" ..
    "格里芬清空了纳尔奇克的威胁\n====================", 10,
      "格里芬战情通报")
    Narchik_Base:Spawn()
end
-- 纳尔奇克占领结束

-- ******************矿水城占领开始
CaptureZone_Minvody = ZONE:New("MinvodyZone")
ZoneCaptureCoalition_Minvody = ZONE_CAPTURE_COALITION:New(CaptureZone_Minvody, SIDE.RED)
ZoneCaptureCoalition_Minvody:__Guard(1)

ZoneCaptureCoalition_Minvody:Start(5, 60)

local MinvodyBase = SPAWN:New("GRIFFIN Minvody Base")

function ZoneCaptureCoalition_Minvody:onenterGuarded(From, Event, To) -- 矿水城占领机场事件
  if From ~= To then
    local tempCoalition = self:GetCoalition()
    if tempCoalition == SIDE.BLUE then
      -- 通报
      MessageToAll("====================\n格里芬战情通报:\n" ..
      "格里芬的部队占领了矿水城\n====================",
        10, "格里芬战情通报")
      if MinvodyBase:GetFirstAliveGroup() then
        MinvodyBase:Spawn()
      end
      
      IRONBLOOD_FIGHTER:SpawnScheduleStop()
      IRONBLOOD_FIGHTER = nil
    elseif tempCoalition == SIDE.RED then
      MessageToAll("格里芬战情通报: 铁血占领了矿水城机场", 10, "格里芬战情通报")
    end
  end
end

function ZoneCaptureCoalition_Minvody:OnEnterAttacked() -- 通报正在被进攻
  local beattacked = self:GetCoalition()
  if beattacked == SIDE.BLUE then
    MessageToAll("====================\n格里芬战情通报:\n" ..
    "矿水城正在被铁血进攻\n====================", 10, "格里芬战情通报")
  else
    MessageToAll("====================\n格里芬战情通报:\n" ..
    "格里芬地面部队正在进攻矿水城\n====================", 10,
      "格里芬战情通报")
  end
end

function ZoneCaptureCoalition_Minvody:onenterEmpty() --当玩家清除完目标后生成蓝方以占领
    MessageToAll("====================\n格里芬战情通报:\n" ..
    "格里芬清空了矿水城的威胁\n====================", 10,
      "格里芬战情通报")
      MinvodyBase:Spawn()
end
-- 矿水城占领结束

-- FARP占领开始
CaptureZone_FARP = ZONE:New("IRONBLOOD FARP")
ZoneCaptureCoalition_FARP = ZONE_CAPTURE_COALITION:New(CaptureZone_FARP, SIDE.RED)
ZoneCaptureCoalition_FARP:__Guard(1)

ZoneCaptureCoalition_FARP:Start(5, 60)

local Farp_Base = SPAWN:New("GRIFFIN FARP SUPPORT-1")

function ZoneCaptureCoalition_FARP:onenterGuarded(From, Event, To) -- 纳尔奇克占领机场事件
  if From ~= To then
    local tempCoalition = self:GetCoalition()
    if tempCoalition == SIDE.BLUE then
      FARP_CLIENTS:ForEachClient(function(client)
        USERFLAG:New(tostring(client.ClientName)):Set(0) -- enable clients
      end)
      -- 通报
      MessageToAll("====================\n格里芬战情通报:\n" ..
      "格里芬的部队占领了前线直升机坪,现在可以使用该停机坪的直升机\n====================",
        10, "格里芬战情通报")
      if Narchik_Base:GetFirstAliveGroup() then
        Narchik_Base:Spawn()
      end
    elseif tempCoalition == SIDE.RED then
      MessageToAll("格里芬战情通报: 铁血占领了前线直升机坪", 10, "格里芬战情通报")
    end
  end
end

function ZoneCaptureCoalition_FARP:OnEnterAttacked() -- 通报正在被进攻
  local beattacked = self:GetCoalition()
  if beattacked == SIDE.BLUE then
    MessageToAll("====================\n格里芬战情通报:\n" ..
    "前线直升机坪正在被铁血进攻\n====================", 10, "格里芬战情通报")
  else
    MessageToAll("====================\n格里芬战情通报:\n" ..
    "格里芬地面部队正在进攻前线直升机坪\n====================", 10,
      "格里芬战情通报")
  end
end

function ZoneCaptureCoalition_FARP:onenterEmpty() --当玩家清除完目标后生成蓝方以占领
    MessageToAll("====================\n格里芬战情通报:\n" ..
    "格里芬清空了前线直升机坪的威胁\n====================", 10,
      "格里芬战情通报")
      Farp_Base:Spawn()
end
-- FARP占领结束